import {
  transaction,
  payNotice,
  jybtradeorderInfo,
  jybtradeorderCancel,
} from "@/api/trading.js";
import store from "@/store";
import { statusArr } from "@/constant";
export default {
  data() {
    return {
      payType: [
        {
          title: "支付宝",
          key: 1,
          style: "color:red",
        },
        {
          title: "微信",
          key: 2,
          style: "color:#0ED85B",
        },
        {
          title: "银行卡",
          key: 3,
          style: "color:#aaa",
        },
      ],
      uploadImage: "",
      orderInfo: {},
    };
  },
  computed: {
    loaginUid() {
      return store.state.app.uid;
    },
  },
  methods: {
    // 订单取消
    cancelHandler() {
      const that = this;
      uni.showLoading({
        title: "订单取消中",
      });
      jybtradeorderCancel(this.orderInfo.id)
        .then((res) => {
          that.$util.Tips({
            title: "取消成功",
          });
          this.getJybtradeorderInfoList(this.orderInfo.no);
        })
        .then((err) => {
          that.$util.Tips({
            title: err,
          });
        });
    },
    toCenter() {
      uni.redirectTo({
        url: "/pages/center_service/center_service",
      });
    },
    // 订单信息获取
    getJybtradeorderInfoList(no = "202404270137019791") {
      jybtradeorderInfo(no).then((res) => {
        this.orderInfo = res.data || {};
      });
    },
    statusChanges(status) {
      return statusArr.filter((item) => item.key == status)[0] || {};
    },
    payTypeChanges(type) {
      return this.payType.filter((item) => item.key == type)[0] || {};
    },
    // 上传图片
    upLoadPic() {
      let that = this;
      that.$util.uploadImageOne(
        {
          url: "user/upload/image",
          name: "multipart",
          model: "user",
          pid: "0",
        },
        function (res) {
          const { url } = res.data;
          that.uploadImage = url;
        }
      ),
        function (err) {
          that.$util.Tips({
            title: err,
          });
        };
    },

    // 付款
    payClick(no, isBuy) {
      if (isBuy) {
        if (!this.uploadImage) {
          this.$util.Tips({
            title: "请上传凭证",
          });
          return;
        }
        const _url = this.uploadImage.split("aliyuncs.com/")[1] || "";
        payNotice(no, _url)
          .then((res) => {
            this.getJybtradeorderInfoList(this.orderInfo.no);
          })
          .catch((err) => {
            this.$util.Tips({
              title: err,
            });
          });
      }
    },
    // 放币
    paidClick(no, isBuy) {
      console.log(isBuy);
      if (isBuy) {
        transaction(no)
          .then((res) => {
            this.getJybtradeorderInfoList(this.orderInfo.no);
          })
          .catch((err) => {
            this.$util.Tips({
              title: err,
            });
          });
      }
    },
  },
};
